FROM ubuntu:20.04

# 使用root用户
USER root

# 建立挂载路径以及apt换源
RUN mkdir /opt/notebooks \
&& sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list \
&& apt update -y \
&& apt install -y nodejs npm vim curl wget python3 python3-pip -y \
&& alias python=python3

# 安装jupyterlab3及插件，并生成配置文件
RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ "jupyterlab==3.0.5" \
&& jupyter-lab --generate-config \
#&& chmod -R 777 /root/.common/jupyter_lab_config.py \
&& chmod -R 777 /opt/notebooks
#&& pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ jupyterlab-language-pack-zh-CN \
#&& pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ jupyterlab-lsp==3.2.0 common-lsp==1.1.1 \
#&& pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ jupyterlab_code_formatter \
#&& pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ python-language-server[all] \
#&& pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ black isort
#
## 安装常用库
#RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ pandas \
#&& pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ numpy \
#&& pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ matplotlib \
#&& pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ tqdm \
#&& pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ scikit-learn \
#&& pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ ipywidgets \
#&& pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ ipympl

# 安装R kernel
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

RUN /bin/bash -c '/bin/echo -e "\nyes\n\nyes" | /bin/bash Miniconda3-latest-Linux-x86_64.sh'
 
RUN /root/miniconda3/bin/conda install -y r==3.6 \
&& /root/miniconda3/bin/conda install -y r-IRkernel

COPY ./add_kernel.r ./add_kernel.R

RUN /root/miniconda3/bin/Rscript add_kernel.R
 
# 设置挂载路径
VOLUME /opt/notebooks

# 设置映射端口
# EXPOSE $PORT

# 设置容器启动时运行的命令
CMD jupyter lab --notebook-dir=/opt/notebooks --ip='*' --port=$PORT --allow-root --no-browser

